<?php
/**
 * 
 * @todo description of this class
 * 
 * @author Alton Crossley <crossleyframework@nogahidebootstrap.com>
 * @package Crossley Framework
 *  
 * @copyright Copyright (c) 2003-2009, Nogaide BootStrap INC. All rights reserved.
 * @license BSD http://opensource.org/licenses/bsd-license.php
 * @version $Id:$
 * 
 */
class X_Filter_Period implements X_Filter_Interface
{
    
    /**
     * Defined by Zend_Filter_Interface
     *
     * Returns the string $value, removing all but alphabetic and digit characters
     *
     * @param  string $value
     * @return string
     */
    public function filter($sValue)
    {
        
        $sPattern = '/P(\d{1,2}Y)*(\d{1,2}M)*(\d{1,2}D)*T(\d{1,2}H)*(\d{1,2}M)*(\d{1,2}S)*/u';
        
        return preg_replace($sPattern, '', (string) $sValue);
    }
    /**
     * allow static call of the filter
     *
     * @param string|array $xValue
     * @return string
     */
    static function go($xValue)
    {
        $sSelf = __CLASS__;
        $oFileter = new $sSelf();
        
        if (is_array($xValue))
        {
            $aFiltered = array();
            foreach ($xValue as $sKey => $xValue)
            {
                $aFiltered[$sKey] = $oFileter->filter((string)$xValue);
            }
            return $aFiltered;
        }
        else
        {
            return $oFileter->filter((string)$xValue);
        }
        
    }
}
